﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fusion
{
	/// <summary> Runs specified void delegate every span </summary>
	public class Ticker
	{
		public VoidDelegate Tick;
		public bool running;
		public float span;
		float count;


		public Ticker( float s, VoidDelegate del )
		{
			span = s;
			Tick = del;
			running = true;
		}

		public void Update()
		{
			if( running == false )
				return;

			count += Engine.period;

			if( count >= span )
			{
				if( Tick != null )
					Tick();
				count -= span;
			}
		}

		public void Start()
		{
			running = true;
			count = 0;
		}

		public void Stop()
		{
			running = false;
			count = 0;
		}

		public void Reset()
		{
			count = 0;
		}
	}
}
